package com.yy.controller.user;


import com.yy.dto.ShoppingCartDTO;
import com.yy.entity.ShoppingCart;
import com.yy.result.Result;
import com.yy.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

/**
 * 购物车
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "C端-购物车接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO dto){
        shoppingCartService.addShoppingCart(dto);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        List<ShoppingCart> shoppingCartList = shoppingCartService.list();
        return Result.success(shoppingCartList);
    }

    @PostMapping("/sub")
    public Result delete(@RequestBody ShoppingCartDTO dto){
        Result result = shoppingCartService.delete(dto);
        return result;
    }

    @DeleteMapping("/clean")
    public Result deleteAll(){
        shoppingCartService.deleteAll();
        return Result.success();
    }

}
